package com.handpay.zztong.hp.ui;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.handpay.zztong.hp.R;

public class ZZTShowDialog<T extends View> {
	private Context context;
	private Dialogcallback dialogcallback;
	private Dialog dialog;
	private Button sure, cancel;
	private T mContentView;

	public ZZTShowDialog() {
		super();
	}


	public ZZTShowDialog(Context context, int view_id,int dialog_theme) {
		this.context = context;
		dialog = new Dialog(context, dialog_theme);
		dialog.setContentView(view_id);
		sure = (Button) dialog.findViewById(R.id.ok);
		if (sure != null){


		sure.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (dialogcallback != null) {
					dialogcallback.ButtonOk();
				}
			}
		});
		}
		cancel = (Button) dialog.findViewById(R.id.cancle);
		if (cancel !=null)
		cancel.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (dialogcallback != null) {
					dialogcallback.ButtonCancel();
				}
				dismiss();
			}
		});
		dialog.setCanceledOnTouchOutside(false);
		dialog.setCancelable(false);
	}

	public ZZTShowDialog(Context context, T view, int dialog_theme) {
		this.context = context;
		this.mContentView = view;
		dialog = new Dialog(context, dialog_theme);
		dialog.setContentView(view);
	}

	public T getContentView() {
		return mContentView;
	}

	public void show() {
		dialog.show();
	}

	public void hide() {
		dialog.hide();
	}

	public void dismiss() {
		dialog.dismiss();
	}

	public interface Dialogcallback {
		void ButtonOk();

		void ButtonCancel();
	}

	public void setDialogCallback(Dialogcallback dialogcallback) {
		this.dialogcallback = dialogcallback;
	}

	public Dialog getDialog(){
		return dialog;
	}
}
